#include "BlockingQueue.h"

#include <folly/logging/xlog.h>

namespace nexus {

// template <class T>
// BlockingQueue<T>::BlockingQueue(size_t size) : queue_(100) {}

template <typename T>
void
BlockingQueue<T>::read(T& data) {
  if (folly::ProducerConsumerQueue<T>::isEmpty()) {
    baton_.wait();
  }
  folly::ProducerConsumerQueue<T>::read(data);
  baton_.reset();
}

template <class T>
void
BlockingQueue<T>::write(T&& data) {
  folly::ProducerConsumerQueue<T>::write(data);
  baton_.post();
}

} // namespace nexus